
window.setDemoConfig = function () {
  console.log("设置demo_config")
  const server_addr = document.getElementsByName('server_addr')[0].value
  const cuid = document.getElementsByName('cuid')[0].value
  const joinpwd = document.getElementsByName('joinpwd')[0].value
  const nick_name = document.getElementsByName('nickname')[0].value
  demo_config.server.ip = server_addr.split(':')[0]
  demo_config.server.https_port = server_addr.split(':')[1]
  demo_config.meeting.cuid = cuid
  demo_config.meeting.joinpwd = joinpwd
  demo_config.meeting.nick_name = nick_name
}

window.getDemoConfig = function () {
  console.log("获取DemoConfig中的服务器地址、会议号码、入会/主持密码、会中显示的姓名，显示到input输入框")
  document.getElementsByName('server_addr')[0].value = demo_config.server.ip + ':' + demo_config.server.port
  document.getElementsByName('cuid')[0].value = demo_config.meeting.cuid
  document.getElementsByName('joinpwd')[0].value = demo_config.meeting.joinpwd
  document.getElementsByName('nickname')[0].value = demo_config.meeting.nick_name
}

/**
 * 为 Video 元素的属性赋值；
 *
 * @param elementId Video 元素的 id；
 * @param stream 视频流 URL；
 * @returns {boolean} 如果为 true， 表示赋值成功， 否则表示赋值失败；
 */
window.setPropForVideo = function(elementId, stream) {
    const video = document.getElementById(elementId);
    if (video) {
        video.srcObject = stream;
        video.muted = true;
        video.autoplay = true;

        return true;
    }
    return false;
}